<template>
	<view class="info_top">
		<view class="w-690 info-bg-title" style="height: 265rpx;">
			<view class="left-balck d-flex align-items">
				<image src="../static/back@1x.png" @click="go_black" mode="widthFix" class="go_back"></image>
				<view class="line"></view>
				<image src="../static/home@1x.png" @click="goHome" mode="widthFix" class="go_index"></image>
			</view>
			<view class="title">施工队信息发布</view>
			<view class="right"></view>
		</view>
		<view class="w-690 content-list">
			<view class="w-650 d-flex margin-top-30">
				<view class="fabu_title">发布类型</view>
				<view class="radio_list">
					<u-radio-group v-model="radiovalue1" placement="row">
						<u-radio activeColor="#FF6400" :customStyle="{marginLeft: '15rpx',marginBottom:'15rpx'}"
							v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.id"
							@change="radioChange">
						</u-radio>
					</u-radio-group>
				</view>
			</view>
			
			<view class="" v-if="radiovalue1 == 0">
				<view class="w-650 d-flex align-items margin-top-30">
					<view class="fabu_title">需要工种</view>
					<view class="righttx d-flex align-items" @click="choose_gongzhong">
						<view :class="gongzhong == '请选择工种' ? 'top-txt_true' : 'top-txt'">{{gongzhong}}</view>
						<image class="qm" src="../static/right.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="w-650 margin-top-30 d-flex align-items justify-content-space-between">
					<view class="d-flex align-items">
						<view class="cs">需要人数</view>
						<input type="text" class="miankuan" v-model="miankuan" />
						<view class="cs">人</view>
					</view>
					<view class="d-flex align-items">
						<view class="cs">预计工期</view>
						<input type="text" class="miankuan" v-model="jinshen" />
						<view class="cs">天</view>
					</view>
				</view>
				<view class="w-650 margin-top-30 d-flex align-items">
					<view class="cs">手机号码</view>
					<view class="righttx">
						<input type="text" class="phone-txt" placeholder="请输入手机号" v-model="phone" />
					</view>
				</view>
				<view class="w-650 margin-top-30">
					<view class="cs">信息内容</view>
					<view class="">
						<textarea name="" class="xinxi_content" placeholder="请输入信息内容" id="" cols="30"
							rows="10"></textarea>
					</view>
				</view>
			</view>
			<view class="" v-if="radiovalue1 == 1">
				<view class="w-650 d-flex align-items margin-top-30">
					<view class="fabu_title">证件选择</view>
					<view class="righttx d-flex align-items" @click="choose_card">
						<view :class="card_txt == '请选择证件种类' ? 'top-txt_true' : 'top-txt'">{{card_txt}}</view>
						<image class="qm" src="../static/right.png" mode="widthFix"></image>
					</view>
				</view>
				<!-- 证件图片 -->
				<view class="w-650 margin-top-30">
					<view class="fabu_title">证件图片</view>
					<view class="zhengjian">
						<u-upload width="127rpx" height="127rpx" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="1">
							<image :src="src" class="shangchuanimg" v-if="avatar"></image>
							<image src="../static/upload.png" class="shangchuanimg" v-else></image>
						</u-upload>
					</view>
				</view>
				<view class="w-650 margin-top-30 d-flex align-items">
					<view class="cs">手机号码</view>
					<view class="righttx">
						<input type="text" class="phone-txt" placeholder="请输入手机号" v-model="phone" />
					</view>
				</view>
				<view class="w-650 margin-top-30">
					<view class="cs">信息内容</view>
					<view class="">
						<textarea name="" class="xinxi_content" placeholder="请输入备注信息" id="" cols="30"
							rows="10"></textarea>
					</view>
				</view>
			</view>
			<view class="" v-if="radiovalue1 == 2">
				<view class="w-650 margin-top-30 d-flex align-items justify-content-space-between">
					<view class="d-flex align-items">
						<view class="cs">输入面宽</view>
						<input type="text" class="miankuan" v-model="miankuan" />
						<view class="cs">米</view>
					</view>
					<view class="d-flex align-items">
						<view class="cs">输入进深</view>
						<input type="text" class="miankuan" v-model="jinshen" />
						<view class="cs">米</view>
					</view>
				</view>
				<view class="w-650 margin-top-30 d-flex align-items justify-content-space-between">
					<view class="d-flex align-items">
						<view class="cs">房屋面积</view>
						<input type="text" class="miankuan" v-model="miankuan" />
						<view class="cs">m²</view>
					</view>
					<view class="d-flex align-items">
						<view class="cs">造价</view>
						<input type="text" class="miankuan" v-model="jinshen" />
						<view class="cs">元</view>
					</view>
				</view>
				<!-- 案例主图 -->
				<view class="w-650 margin-top-30">
					<view class="fabu_title">案例主图 <text class="zhutu">（第一张图为封面图）</text> </view>
					<view class="zhengjian">
						<u-upload width="127rpx" height="127rpx" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="1">
							<image :src="src" class="shangchuanimg" v-if="avatar"></image>
							<image src="../static/upload.png" class="shangchuanimg" v-else></image>
						</u-upload>
					</view>
				</view>
				<view class="w-650 margin-top-30">
					<view class="cs">标题</view>
					<view class="">
						<textarea name="" class="xinxi_content" placeholder="请输入标题" id="" cols="30"
							rows="10"></textarea>
					</view>
				</view>
				<!-- 详情 -->
				<view class="w-650 margin-top-30">
					<view class="fabu_title">详情</view>
					<view class="zhengjian">
						<u-upload width="127rpx" height="127rpx" :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="1">
							<image :src="src" class="shangchuanimg" v-if="avatar"></image>
							<image src="../static/upload.png" class="shangchuanimg" v-else></image>
						</u-upload>
					</view>
				</view>
				<view class="w-650 margin-top-30">
					<view class="">
						<textarea name="" class="xinxi_content" placeholder="请输入标题" id="" cols="30"
							rows="10"></textarea>
					</view>
				</view>
			</view>
			<view class="liji-btn">
				<u-button color="#FF6400" @click="get_zaojia" text="确认发布"></u-button>
			</view>
		</view>
		
		<u-datetime-picker ref="datetimePicker" @confirm="confirm_time" @cancel="show_time = false" :show="show_time" v-model="nowtime" mode="date"
			:formatter="formatter"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		tree
	} from '@/api/citys.js'
	export default {
		data() {
			return {
				radiolist1: [{
						id: 0,
						name: '雇工信息',
						disabled: false
					},
					{
						id: 1,
						name: '证件挂靠信息',
						disabled: false
					},
					{
						id: 2,
						name: '施工案例',
						disabled: false
					}
				],
				fileList1:[],
				fileList2:[],
				avatar: '',
				src: require('../static/upload.png'),
				radiovalue1: 0,
				miankuan: '',
				jinshen: '',
				tingyuan: '',
				cengshu: '',
				lutai: '',
				phone: '',
				columns: [],
				gongzhong:'请选择工种',
				card_txt:'请选择证件种类',
				value: 0,
				range: [{
						value: 0,
						text: "砖混结构"
					},
					{
						value: 1,
						text: "混凝土灌注"
					},
					{
						value: 2,
						text: "钢架结构"
					}
				],
				show_time: false,
				nowtime: Number(new Date()),
			}
		},
		onLoad() {
			
		},
		onReady() {
			// 微信小程序需要用此写法
			this.$refs.datetimePicker.setFormatter(this.formatter)
		},
		filters: {
			formatDates(num) {
				let date = new Date(num);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				return y + '-' + MM + '-' + d; //年月日
			}
		},
		methods: {
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			// 选择装修时间
			chooseTime(){
				this.show_time = true
			},
			confirm_time(e){
				console.log("目前选择的时间是",e);
				this.zhuangxiu_time = e.value
				this.nowtime = e.value
				this.show_time = false
			},
			
			go_black() {
				uni.navigateBack({
					delta: 1
				})
			},
			radioChange(e){
				console.log("选择了第几个",e);
			},
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			chooseCity() {
				console.log("eeeee", this.columns);
				this.showcity = true
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				var url = event.file[0].url
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				console.log("00000000000000", lists);
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						fullurl: result.fullurl,
						url_noyuming: result.url
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				var that = this
				console.log("url有没有值", url);
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: upFile,
						filePath: url,
						name: 'file',
						formData: {
							user: 'test',
							token: uni.getStorageSync('token')
						},
						success: (res) => {
							console.log("s111111111111111______", res);
							var data = JSON.parse(res.data);
							resolve(data.data)
						}
					});
				})
			},
			
			cancel(e) {
				this.showcity = false
			},
			
			
		}
	}
</script>

<style>
	.zhutu{
		font-size: 24rpx;
		color: #999999;
	}
	.zhengjian{
		margin-top: 20rpx;
	}
	.shangchuanimg {
		width: 127rpx;
		height: 127rpx;
		border: 1px solid #eee;
		display: block;
		margin: auto;
		overflow: hidden;
	}
	/deep/.u-radio-group--row {
		flex-wrap: wrap;
	}
	.radio_list{
		width: 500rpx;
	}
	.liji-btn {
		width: 630rpx;
		margin: auto;
		margin-top: 30rpx;
	}

	.xinxi_content {
		width: 590rpx;
		height: 160rpx;
		background-color: #F5F5F5;
		border-radius: 12rpx;
		margin: auto;
		font-size: 24rpx;
		color: #000000;
		margin-top: 30rpx;
		padding: 20rpx;
	}

	.jiegou {
		/* width: 170rpx; */
		margin: 0 16rpx;
	}

	.miankuan {
		width: 120rpx;
		height: 64rpx;
		border-radius: 8rpx;
		border: 2rpx solid #EEEEEE;
		opacity: 1;
		margin: 0 16rpx;
		text-align: center;
	}

	.qm {
		width: 18rpx;
		display: block;
		padding: 10rpx 20rpx;
		margin-left: 10rpx;
	}

	.top-txt_true {
		width: 501rpx;
		font-size: 24rpx;
		color: #999999;
		text-align: right;
		padding-left: 10rpx;
	}

	.mianji_w {
		width: 450rpx;
		height: 64rpx;
		border-radius: 8rpx;
		border: 2rpx solid #EEEEEE;
		opacity: 1;
		margin-left: 16rpx;
		margin-right: 15rpx;
	}
	.phone-txt{
		width: 500rpx;
		height: 64rpx;
		font-size: 24rpx;
		color: #333333;
		padding-left: 10rpx;
	}

	.top-txt {
		width: 500rpx;
		font-size: 24rpx;
		color: #333333;
		text-align: right;
		padding-left: 10rpx;
	}

	.cs {
		font-size: 28rpx;
		color: #333333;
	}

	.righttx {
		width: 501rpx;
		height: 64rpx;
		border-radius: 8rpx;
		border: 2rpx solid #EEEEEE;
		opacity: 1;
		margin-left: 16rpx;
	}

	.fabu_title {
		font-size: 28rpx;
		color: #333333;
	}

	.content-list {
		width: 690rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx 0;
	}

	/* 顶部自定义nav */
	.info-bg-title {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.right {
		width: 174rpx;
	}

	.title {
		font-size: 34rpx;
		font-weight: normal;
		text-align: center;
		color: #FFFFFF;
	}

	.left-balck {
		width: 174rpx;
		height: 64rpx;
		border-radius: 32rpx;
		justify-content: space-around;
		border: 1px solid rgb(255, 255, 255, 0.6);
	}

	.line {
		width: 1rpx;
		height: 37rpx;
		opacity: 0.6;
		background: #FFFFFF;
	}

	.go_index {
		width: 40rpx;
		display: block;
	}

	.go_back {
		width: 40rpx;
		display: block;
	}

	.info_top {
		width: 750rpx;
		height: 434rpx;
		background: url('https://lianfan.nccpu.cn/image/info_bg.png') no-repeat;
		background-size: 100% auto;
	}

	/* end */
	page {
		background-color: #F7F8FB;
	}
</style>